package com.transaction.demo.message;

import javax.validation.Valid;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.transaction.demo.common.util.Result;
import com.transaction.demo.common.util.ResultPage;
import com.transaction.demo.message.vo.req.ReSendAllDeadMessageByQueueNameReqVo;
import com.transaction.demo.message.vo.req.TransactionMessageAddReqVo;
import com.transaction.demo.message.vo.req.TransactionMessageListReqVo;
import com.transaction.demo.message.vo.req.WaitOrSendMessageListReqVo;
import com.transaction.demo.message.vo.resp.TransactionMessageRespVo;

/**
 * 描述：消息相关操作
 * 作者：马庆智
 * 日期：2023/04/26 10:29:01
 */
@FeignClient(value = "demo-message-provider", fallback = MessageServiceHystrix.class, path = "/message/transactionMessage")
public interface MessageService {

	/**
	 * 查询列表
	 *
	 * @param record 请求参数
	 * @return TransactionMessageResp
	 * @author 马庆智
	 * @date: 2023/04/26 10:29:01
	 */
	@PostMapping("/queryTransactionMessageList")
	Result<ResultPage<TransactionMessageRespVo>> queryTransactionMessageList(
			@RequestBody @Valid TransactionMessageListReqVo record);

	/**
	 * 查询待确认或者发送中的的消息
	 *
	 * @param record 请求参数
	 * @return TransactionMessageResp
	 * @author 马庆智
	 * @date: 2023/04/26 10:29:01
	 */
	@PostMapping("/queryWaitOrSendMessageList")
	public Result<ResultPage<TransactionMessageRespVo>> queryWaitOrSendMessageList(
			@RequestBody @Valid WaitOrSendMessageListReqVo record);

	/**
	 * 预存储消息.
	 * @param transactionMessage 消息
	 * @return id
	 * @author 马庆智
	 * @date: 2023/4/27 9:55
	 */
	@PostMapping("/queryTransactionMessage")
	Result<Integer> saveMessageWaitingConfirm(@RequestBody @Valid TransactionMessageAddReqVo transactionMessage);

	/**
	 * 确认并发送消息.
	 *
	 * @param messageId 消息id
	 * @return id
	 * @author 马庆智
	 * @date: 2023/4/27 10:01
	 */
	@GetMapping("/confirmAndSendMessage")
	Result<Integer> confirmAndSendMessage(@RequestParam("messageId") String messageId);

	/**
	 * 存储并发送消息.
	 * @param transactionMessage 消息
	 * @return id
	 * @author 马庆智
	 * @date: 2023/4/27 9:55
	 */
	@PostMapping("/saveAndSendMessage")
	Result<Integer> saveAndSendMessage(@RequestBody @Valid TransactionMessageAddReqVo transactionMessage);

	/**
	 * 直接发送消息.
	 * @param transactionMessage 消息
	 * @return id
	 * @author 马庆智
	 * @date: 2023/4/27 9:55
	 */
	@PostMapping("/directSendMessage")
	Result<Integer> directSendMessage(@RequestBody @Valid TransactionMessageAddReqVo transactionMessage);

	/**
	 * 重发消息.
	 * @param transactionMessage 消息
	 * @return id
	 * @author 马庆智
	 * @date: 2023/4/27 9:55
	 */
	@PostMapping("/reSendMessage")
	Result<Integer> reSendMessage(@RequestBody @Valid TransactionMessageAddReqVo transactionMessage);

	/**
	 * 根据messageId重发某条消息.
	 *
	 * @param messageId 消息id
	 * @return id
	 * @author 马庆智
	 * @date: 2023/4/27 10:01
	 */
	@GetMapping("/reSendMessageByMessageId")
	Result<Integer> reSendMessageByMessageId(@RequestParam("messageId") String messageId);

	/**
	 * 将消息标记为死亡消息.
	 *
	 * @param messageId 消息id
	 * @author 马庆智
	 * @return id
	 * @date: 2023/4/27 10:01
	 */
	@PutMapping("/setMessageToAreadlyDead")
	Result<Integer> setMessageToAreadlyDead(@RequestParam("messageId") String messageId);

	/**
	 * 根据消息ID获取消息.
	 *
	 * @param messageId 消息id
	 * @return TransactionMessageRespVo
	 * @author 马庆智
	 * @date: 2023/4/27 10:01
	 */
	@GetMapping("/getMessageByMessageId")
	Result<TransactionMessageRespVo> getMessageByMessageId(@RequestParam("messageId") String messageId);

	/**
	 * 根据消息ID删除消息.
	 *
	 * @param messageId 消息id
	 *
	 * @author 马庆智
	 * @date: 2023/4/27 10:01
	 */
	@DeleteMapping("/deleteMessageByMessageId")
	Result<Integer> deleteMessageByMessageId(@RequestParam("messageId") String messageId);

	/**
	 * 重发某个消息队列中的全部已死亡的消息.
	 *
	 * @param message 消息
	 *
	 * @author 马庆智
	 * @date: 2023/4/27 10:01
	 */
	@GetMapping("/reSendAllDeadMessageByQueueName")
	Result<Integer> reSendAllDeadMessageByQueueName(@RequestBody @Valid ReSendAllDeadMessageByQueueNameReqVo message);
}